#include "mygraphicview.h"
#include "mygraphicitem.h"
#include <QCursor>
MyGraphicView::MyGraphicView(QWidget *parent)
    : QGraphicsView{parent}
    , m_graphicscene(nullptr)
{
    setMouseTracking(true);
    m_graphicscene = new MyQGraphicScene(this);
    connect(m_graphicscene, SIGNAL(sigChangeCur(bool)), this, SLOT(slotChangeCur(bool)));
    this->setScene(m_graphicscene);
    this->setCacheMode(QGraphicsView::CacheBackground);
    this->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
}

void MyGraphicView::addNode(eSelectShape eType, QPoint point)
{
    QPoint ps = mapFromParent(point);
    QPointF scenePos = mapToScene(ps);
    m_graphicscene->addNode(eType, scenePos);
}

void MyGraphicView::setPos(QPoint point)
{
    QPoint ps = mapFromParent(point);
    QPointF scenePos = mapToScene(ps);
    m_graphicscene->setPos(scenePos);
}

void MyGraphicView::mouseMoveEvent(QMouseEvent *event)
{
    QGraphicsView::mouseMoveEvent(event);
}

void MyGraphicView::slotChangeCur(bool bchange)
{
    if(bchange)
    {
        this->setCursor(Qt::PointingHandCursor);
    }
    else
    {
        this->unsetCursor();
    }
}
